package com.qianbei.view;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.qianbei.view.db.Box;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;

/**
 * Created by gaoml on 2018/1/22.
 */
public class EpcDataBase implements Comparable<EpcDataBase>{
    private  final String[] TYPE = {"医废小箱", "医废大箱", "医塑小箱", "医塑大箱"};
    public Long id;
    public String epc;
    public  int valid;
    public String rssi;
    public  String tid_user;
    /**
     * 中文 周转箱类型
     */
    public  String boxType;
    public  String boxId;
    /**
     * 周转箱类型 数字类型  1 "医废小箱", 2 "医废大箱", 3 "医塑小箱", 4 "医塑大箱
     */
    public  String typeValue;

    public EpcDataBase(String e, int v, String rssi, String tid_user) {
        // TODO Auto-generated constructor stub
        epc = e;
        valid = v;
        this.rssi = rssi;
        this.tid_user = tid_user;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EpcDataBase that = (EpcDataBase) o;

        if(!TextUtils.isEmpty(epc) && !TextUtils.isEmpty(that.epc)){
            return epc.equals(that.epc);
        }

        if(!TextUtils.isEmpty(boxId) && !TextUtils.isEmpty(that.boxId)){
            return boxId.equals(that.boxId);
        }

        return false;
    }

    @Override
    public int hashCode() {
        return epc.hashCode();
    }

    public String getRssi() {
        return rssi;
    }

    public void setRssi(String rssi) {
        this.rssi = rssi;
    }

    @Override
    public String toString() {
        if (TextUtils.isEmpty(epc)) {
            return  "";
        } else {
            if(epc.length()>13){
                return epc.substring(14);
            } else {
                return epc;
            }

        }
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEpc() {
        return this.epc;
    }

    public void setEpc(String epc) {
        this.epc = epc;
    }

    public int getValid() {
        return this.valid;
    }

    public void setValid(int valid) {
        this.valid = valid;
    }

    public String getTid_user() {
        return this.tid_user;
    }

    public void setTid_user(String tid_user) {
        this.tid_user = tid_user;
    }

    public String getBoxType() {
        return this.boxType;
    }

    public void setBoxType(String boxType) {
        this.boxType = boxType;
    }

    public String getBoxId() {
        return this.boxId;
    }

    public void setBoxId(String boxId) {
        this.boxId = boxId;
    }

    public String getTypeValue() {
        return typeValue;
    }

    public void setTypeValue(String typeValue) {
        this.typeValue = typeValue;
    }

    /**
     * Compares this object to the specified object to determine their relative
     * order.
     *
     * @param another the object to compare to this instance.
     * @return a negative integer if this instance is less than {@code another};
     * a positive integer if this instance is greater than
     * {@code another}; 0 if this instance has the same order as
     * {@code another}.
     * @throws ClassCastException if {@code another} cannot be converted into something
     *                            comparable to {@code this} instance.
     */
    @Override
    public int compareTo(@NonNull EpcDataBase another) {

        EpcDataBase other = (EpcDataBase) another;
        if (other.getTypeValue() != null && other.getTypeValue().trim().length() > 0
                && this.getTypeValue() != null && this.getTypeValue().trim().length() > 0) {
            if (other.getTypeValue().equals(this.getTypeValue())) {
                return 0;
            }
            int thisVal = 0;
            int otherVal = 0;
            if (other.getTypeValue().equals("2") || other.getTypeValue().equals("4")) {
                otherVal = 1;
            }else{
                otherVal = 0;
            }

            if (this.getTypeValue().equals("2") || this.getTypeValue().equals("4")) {
                thisVal = 1;
            }else{
                thisVal = 0;
            }


            if(thisVal>otherVal){
                return -1;
            }else{
                return 1;
            }
        }

        if(other.getEpc()==null||other.getEpc().trim().length()==0){
            return -1;
        }

        return 0;


    }

    public void setTypeAndNum(Box box){
        if(box==null){
            return;
        }

        this.boxId = box.getBoxNum();
        this.boxType  = TYPE[box.getBoxType()];
        this.typeValue = String.valueOf(box.getBoxType());
    }


}